import requests
from datetime import datetime

# 测试打点

def request_api(date, start_hour, end_hour, filter_value, keywords):
    base_url = "http://3.1.52.81:7912/log/grep"

    # 将日期格式化为YYYYMMDD
    formatted_date = date.strftime("%Y%m%d")

    # 使用集合记录找到的 filter 和 keyword 组合（自动去重）
    found_combinations = set()
    not_found_combinations = set()

    # 遍历指定的小时段
    for hour in range(start_hour, end_hour + 1):
        # 构造文件名中的小时部分
        hour_str = f"{hour:02d}"  # 格式化为两位数，如01, 02, ..., 23

        # 构造完整的文件路径
        filepath = f"apps/ga-api/h5_{formatted_date}{hour_str}.log"

        # 遍历所有的keywords
        for keyword in keywords:
            # 构造请求参数
            params = {
                "filepath": filepath,
                "count": 99999,
                "filter": filter_value,
                "keywords": keyword
            }

            # 发送GET请求
            response = requests.get(base_url, params=params)

            # 检查响应状态码和内容
            if response.status_code == 200 and response.text.strip():  # 假设非空响应表示找到
                found_combinations.add((filter_value, keyword))
            else:
                not_found_combinations.add((filter_value, keyword))

    # 返回汇总结果
    return found_combinations, not_found_combinations


def main():
    # 参数化传递
    date = datetime(2025, 3, 18)  # 日期
    start_hour = 14  # 开始小时
    end_hour = 18  # 结束小时
    filter_value = "checkin_detail"  # filter参数
    keywords = ["get_task", "get_reward"]  # keywords参数列表  keywords = ["get_task", "get_reward", "whatsapp", "telegram", "instagram"]

    # 调用函数请求接口
    found_combinations, not_found_combinations = request_api(date, start_hour, end_hour, filter_value, keywords)

    # 输出汇总结果
    print("已找到的打点：")
    for combination in found_combinations:
        print(f"Filter: {combination[0]}, Keyword: {combination[1]}")

    print("\n未找到的打点：")
    for combination in not_found_combinations:
        print(f"Filter: {combination[0]}, Keyword: {combination[1]}")


if __name__ == "__main__":
    main()